﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataTier;
using DbLayer;

namespace BusinessTier
{

    public class StationCtr
    {

        private static StationCtr _instance = null;
        private IDbStation _dbStation = DbStation.Instance;

        private StationCtr()
        {
        }

        public static StationCtr Instance
        {

            get
            {

                if (_instance == null)
                {
                    _instance = new StationCtr();
                }

                return _instance;

            }

        }

        public void AddStation(string address, int zipCode, int nrOfBatteries, Location location)
        {
            _dbStation.AddStation(new Station(address, zipCode, nrOfBatteries, location));
        }

        public bool ReserveBattery(Station station)
        {

            bool success = false;

            if (station.AvailableBatteries > 0)
            {

                station.AvailableBatteries -= 1;
                _dbStation.UpdateStation(station);

                success = true;

            }

            return success;

        }

        public void AddBattery(Station station)
        {
            station.AvailableBatteries += 1;
            _dbStation.UpdateStation(station);
        }

        public Station GetStation(Location location)
        {
            return _dbStation.GetStation(location.Id);
        }

        public Station GetStation(int stationId)
        {
            return _dbStation.GetStation(stationId);
        }

        public IList<Station> GetAllStations()
        {
            return _dbStation.GetAllStations();
        }

        public void UpdateStation(Station station)
        {
            //_dbStation.UpdateStation(station);
        }

        public void RemoveStation(int stationId)
        {
            throw new NotImplementedException();
        }

    }

}
